package com.itheima.controller.backend;

import com.itheima.common.entity.Result;
import com.itheima.service.backend.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 统计分析接口
 */
@RestController
@RequestMapping( "/report")
@Slf4j
public class ReportController {

    @Autowired
    private ReportService reportService;

    /**
     * 会员数量统计
     * @return
     */
    @GetMapping("/getMemberReport")
    public Result getMemberReport() {
        try {
            return new Result(true,"会员数据统计成功",reportService.getMemberReport());
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"会员数据统计失败");
        }
    }

    /**
     * 预约套餐占比统计
     * @return
     */
    @GetMapping("/getSetmealReport")
    public Result getSetmealReport() {
        try {
            return new Result(true,"套餐占比统计成功",reportService.getSetmealReport());
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"套餐占比统计失败");
        }
    }

    /**
     *  运营数据统计
     * @return
     */
    @GetMapping("/getBusinessReportData")
    public Result getBusinessReport() {
        try {
            return new Result(true,"运营数据统计成功",reportService.getBusinessReport());
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"运营数据统计失败");
        }
    }

    /**
     * 导出运营数据报表
     * @param request
     * @param response
     * @return
     */
    @GetMapping("/exportBusinessReport")
    public Result exportBusinessReport(HttpServletRequest request, HttpServletResponse response) {
        try {
            reportService.exportBusinessReport(request,response);
            return new Result(true,"导出报表成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"导出报表失败");
        }
    }
}
